<template>
    <div>
        <div class="mui-numbox" data-numbox-min='1' data-numbox-max='9'>
        <!-- <div class="mui-numbox" data-numbox-min='1' :data-numbox-max='max'> -->
            <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
            <input id="test" class="mui-input-numbox" type="number" :value="initcount" @change="countChange" ref="numBox"/>
            <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
        </div>
    </div>
</template>

<script>
// 导入mui，初始化数字框
import mui from '../../../lib/mui/js/mui.js'
// 导入mutations映射函数
import {mapMutations} from 'vuex'

export default {
    props:['initcount','id'],
    data:function(){
        return {}
    },
    mounted:function(){
        mui('.mui-numbox').numbox();
    },
    methods:{
        // 把mutations中更新cart中item的count的方法映射过来
        ...mapMutations(['updateCount']),
        countChange:function(){
            // 当数量变化，获取其当前数量
            var currentNum = this.$refs.numBox.value;
            // var currentNum = mui('.mui-numbox').numbox().getValue();
            // 触发事件向父组件传值
            // this.$emit('numTrans',{
            //     id:this.id,
            //     count:parseInt(currentNum)
            // });
            // 更新cart
            this.updateCount({
                id:this.id,
                count:parseInt(currentNum)
            })
        },

    },
}
</script>

<style lang="scss" scoped>

</style>